package com.jindy.module.oaImprestApproval.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.jindy.module.oaDepartApproval.controller.SyOaDepartController;
import com.jindy.module.oaDepartApproval.domain.SyOaDepart;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.jindy.common.annotation.Log;
import com.jindy.common.core.controller.BaseController;
import com.jindy.common.core.domain.AjaxResult;
import com.jindy.common.enums.BusinessType;
import com.jindy.module.oaImprestApproval.domain.SyOaImprest;
import com.jindy.module.oaImprestApproval.service.ISyOaImprestService;
import com.jindy.common.utils.poi.ExcelUtil;
import com.jindy.common.core.page.TableDataInfo;

/**
 * 备用金审批Controller
 * 
 * @author jindy
 * @date 2023-06-01
 */
@RestController
@RequestMapping("/module/oaImprestApproval")
public class SyOaImprestController extends BaseController
{
    private static final Logger LOGGER = LoggerFactory.getLogger(SyOaImprestController.class);

    @Autowired
    private ISyOaImprestService syOaImprestService;

    /**
     * 查询备用金审批列表
     */
    @PreAuthorize("@ss.hasPermi('module:oaImprestApproval:list')")
    @GetMapping("/list")
    public TableDataInfo list(SyOaImprest syOaImprest)
    {
        startPage();
        List<SyOaImprest> list = syOaImprestService.selectSyOaImprestList(syOaImprest);
        return getDataTable(list);
    }

    /**
     * 导出备用金审批列表
     */
    @PreAuthorize("@ss.hasPermi('module:oaImprestApproval:export')")
    @Log(title = "备用金审批", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SyOaImprest syOaImprest)
    {
        List<SyOaImprest> list = syOaImprestService.selectSyOaImprestList(syOaImprest);
        ExcelUtil<SyOaImprest> util = new ExcelUtil<SyOaImprest>(SyOaImprest.class);
        util.exportExcel(response, list, "备用金审批数据");
    }

    /**
     * 获取备用金审批详细信息
     */
    @PreAuthorize("@ss.hasPermi('module:oaImprestApproval:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(syOaImprestService.selectSyOaImprestById(id));
    }

    /**
     * 新增备用金审批
     */
    @PreAuthorize("@ss.hasPermi('module:oaImprestApproval:add')")
    @Log(title = "备用金审批", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SyOaImprest syOaImprest)
    {
        return toAjax(syOaImprestService.insertSyOaImprest(syOaImprest));
    }

    /**
     * 修改备用金审批
     */
    @PreAuthorize("@ss.hasPermi('module:oaImprestApproval:edit')")
    @Log(title = "备用金审批", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SyOaImprest syOaImprest)
    {
        return toAjax(syOaImprestService.updateSyOaImprest(syOaImprest));
    }

    /**
     * 删除备用金审批
     */
    @PreAuthorize("@ss.hasPermi('module:oaImprestApproval:remove')")
    @Log(title = "备用金审批", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(syOaImprestService.deleteSyOaImprestByIds(ids));
    }

    /**
     * 提交申请
     */
    @Log(title = "备用金审批", businessType = BusinessType.UPDATE)
    @PostMapping( "/submitApply/{id}")
    @ResponseBody
    public AjaxResult submitApply(@PathVariable Long id) {
        try {
            SyOaImprest syOaImprest = syOaImprestService.selectSyOaImprestById(id);
            syOaImprestService.submitApply(syOaImprest);
        } catch (Exception e) {
            LOGGER.error("备用金审批提交申请出错",e);
            return error("备用金审批提交申请出错：" + e.getMessage());
        }
        return success();
    }
}
